package com.zf.controller;


import com.zf.pojo.person;
import com.zf.pojo.seat;
import com.zf.service.personService;
import com.zf.service.seatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class personController {

    @Autowired
    personService personService;
    @Autowired
    seatService seatService;

    @GetMapping("/person")
    @CrossOrigin(value = "http://localhost:8080", maxAge = 1800, allowedHeaders = "*")
    public List<person>  queryPerson(){
        List<person> list = personService.queryPersonList();
        return list;
    }

    @ResponseBody
    @PostMapping("delete/{id}")
    @CrossOrigin(value = "http://localhost:8080", maxAge = 1800, allowedHeaders = "*")
    public List<person>  deleteById(@PathVariable Integer id){

        person person = personService.selectById(id);
        int seatId = person.getSeatId();
        String seatLocation = person.getSeatLocation();
        int airplaneId=seatId/100;
        seatService.addSeat(new seat(seatId,seatLocation,airplaneId));
        personService.deletePerson(id);
        return  personService.queryPersonList();
    }

}
